package neu.soft.controller;

import neu.soft.constant.PurchaseOrderType;
import neu.soft.entity.OperationPurchaseOrder;
import neu.soft.facade.SupplyComprehensiveFacade;
import neu.soft.query.PurchaseOrderQuery;
import neu.soft.service.SupplyService;
import neu.soft.util.TypeConvert;
import neu.soft.vo.PageBean;
import neu.soft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/supply")
@CrossOrigin
public class SupplyController {

    @Autowired
    private SupplyService supplyService;

    @Autowired
    SupplyComprehensiveFacade supplyComprehensiveFacade;

    @PostMapping("/page")
    public ResultBean<PageBean<OperationPurchaseOrder>> findByPage(@RequestBody PurchaseOrderQuery purchaseOrderQuery) {

        PageBean<OperationPurchaseOrder> pageBean = supplyService.findByPage(purchaseOrderQuery);
        return ResultBean.success(pageBean);
    }

    //从新供应商购货
    @PostMapping("/supply")
    public ResultBean supplyByNewVendor(@RequestBody Map<String, Object> map) {
        OperationPurchaseOrder operationPurchaseOrder = supplyComprehensiveFacade.purchaseOrderFromVendor(map);
        return ResultBean.success(operationPurchaseOrder);
    }

    //购货单类型传给前端，用于查询
    @GetMapping("/type")
    public ResultBean<List<String>> getPurchaseOrderType(){

        return ResultBean.success(supplyService.getType());
    }


}
